package com.visionet.waveletData.web.repository.robot;

import com.visionet.waveletData.web.entity.robot.Robot;
import com.visionet.waveletData.web.vo.RobotVo;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by hxpeng on 2017/1/10.
 */
@Repository
public interface RobotDao extends JpaRepository<Robot,Long> {

    @Query(value = "from Robot")
    public List<Robot> findAllRobot();

    @Query(value = "from Robot where robot_number = ?1 and is_deleted = 0")
    public Robot findOneByRobotNumber(String robotNumber);

    @Query(value = "from Robot where robot_number = ?1 and company_id =?2 and is_deleted = 0")
    public Robot findOneByRobotNumberAndCompanyId(String robotNumber,String companyId);

//    @Query(value = "from Robot where is_deleted='0' and robot_number like CONCAT('%',:robotNumber,'%')  and id not in (select robotId from RobotGroup where is_deleted='0' and group_id = :groupId)")
//    public List<RobotVo> findAllByRobotNumber(@Param("robotNumber") String robotNumber, @Param("groupId") String groupId);

    public PageImpl<RobotVo> findPageRobot(RobotVo robotVo, Pageable page);

    //向分组中添加机器人中，机器人列表调用分页查询
    public PageImpl<RobotVo> findPageRobotInGroupAddMethod(RobotVo robotVo, Pageable page);

    public int findCountByRobotId(String robotId);

    //找出机器人所在分组是否在播放计划中
    public int checkRobotIsInPlan(String robotNumber);

    //根据计划ID查询出所有的机器人
    public List<Robot> findAllRobotByPlanId(Long planId);
}
